layui.use(['jquery', 'form', 'common', 'croppers', 'formSelects'], function() {
	var $ = layui.jquery;
	var form = layui.form;
	var common = layui.common;
	var croppers = layui.croppers;

	form.on('submit(form)', function(data) {
		$.post('save', data.field, function(data) {
			if (data.state == 'ok') {
				// 成功，跳转到列表页面
				common.toUrl('list');
			} else {
				// 失败，弹出提示
				layer.msg(data.msg, {
					icon: 5,
					anim: 6
				});
			}
		});
		return false;
	});
	croppers.render({
		elem: '#avatarEdit',
		saveW: 200,
		saveH: 200,
		mark: 1/1,
		area: '900px',
		url: common.ctxPath + '/image/upload',
		done: function(data) {
			if (data.state == 'ok') {
				// 成功
				$('#avatarInput').val(data.value);
				$('#avatarImg').prop('src', data.url);
			} else {
				// 失败，弹出提示
				layer.msg(data.msg, {
					icon: 5,
					anim: 6
				});
			}
		}
	});
});